package dbTest.Util;

import java.io.IOException;
import java.io.InputStream;
import java.sql.*;
import java.util.Properties;

/**
 * @Author: Tiangle
 * @Date: 2021/9/26 16:23
 */
public class DBUtil {
    static Connection connection=null;
    public static Connection getConnection() {
        InputStream is = DBUtil.class.getClassLoader().getResourceAsStream("db.properties");
        Properties pr = new Properties();
        try {
            pr.load(is);
        } catch (IOException e) {
            e.printStackTrace();
        }

        String url = (String) pr.get("url");
        String user = (String) pr.get("user");
        String pwd = (String) pr.get("pwd");

        try {
            connection = DriverManager.getConnection(url, user, pwd);
        } catch (
                SQLException e) {
            e.printStackTrace();
        }
        return connection;
    }

    public static void close() {
        try {
            connection.close();
        } catch (SQLException e) {
            e.printStackTrace();
        }
        connection=null;

    }


}
